package com.example.treehole.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.treehole.bean.Course;
import com.example.treehole.mapper.CourseMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Override
    @Transactional
    public boolean addCourse(Course course) {
        int count = baseMapper.countByDayAndClass(course.getDayOfWeek(), course.getClassNumber(), course.getUserid());
        if (count > 0) {
            return false;
        }
        return save(course);
    }

    @Override
    public List<Course> getCoursesByUserId(String userId) {
        return lambdaQuery().eq(Course::getUserid, userId).list();
    }

    @Override
    public boolean deleteCourse(String id) {
        return removeById(id);
    }
}